Daemons are processed as a result of asserting facts. The system handles daemons in a manner similar to the way that it handles rules when forward chaining. When a fact is asserted, all daemons using that fact are examined whether the fact was asserted by a rule, by the "putIntoFact" XCMD, or by another daemon. The daemons are processed in a depth first manner in the order that they appear in the rule base. The following example illustrates the search order:
rule x
if
fact a
then
put 1 into fact d -- assume fact d was asserted
daemon d1
when
fact d = 1 -- daemon 1 uses d and will be examined
then -- first
put 2 into fact e -- the daemon will fire, asserting fact e
-- and causing daemon 3 to be examined
daemon d2
when
fact d = 1 -- daemon 2 will be examined after
then -- daemon 3
put 3 into fact f
daemon d3
when
fact e = 2 -- daemon 3 will be examined
then -- second because it uses fact e.
put 4 into fact g -- If no more daemons use fact e,
-- the system will resume the search
-- for daemons using fact d
Note that daemons can never directly alter the search strategy, even when backward chaining. If the system encounters a fact that is not asserted while processing a daemon, it simply ceases processing of the daemon.
Note also that all daemons using a fact are examined every time a value is assigned to the fact, even if that value is null ("").